#include<stdio.h>
#define N 100
#define NOTFOUND -1

int binary_search(int a[],int n,int x)
{
    int left,right,mid;
    left=0,right=n-1;
    while(left<=right)
    {
        mid=(left+right)*0.618;
        if(x==a[mid])  return(mid);
        if(x<a[mid])   right=mid-1;   //准备查找前半段
        else           left=mid+1;    //准备查找后半段
    }
    return(NOTFOUND);
}

int main()
{
    int n,x,k;
    printf("请输入查找模型数据大小：");
    scanf("%d",&n);
    int array[n];
    printf("请输入查找模型数据样本：");
    for(int i=0;i<n;i++)
    {
        scanf("%d",&array[i]);
    }
    printf("请输入需要查找的数据:");
    scanf("%d",&x);
    k=binary_search(array,n,x);
    if(k==NOTFOUND)  printf("没有找到数据");
    else             printf("找到数据,位置为%d",k);
}